package com.ly.nethub

import android.content.Context
import com.ly.nethub.config.NetHubOptions
import com.ly.nethub.interf.ConnectStatusListener
import com.ly.nethub.interf.INetHubInterface
import com.ly.nethub.interf.OtherMsgCallback
import com.ly.nethub.netty.HeartbeatFactory
import com.ly.nethub.netty.tcp.TcpNetHub

/**
 * 构建长连接客户端类
 * feature create WebSocket client
 */
object NetHubFactory {

    /**
     * 创建Tcp客户端
     * @param context application
     * @param options 配置项
     * @param heartbeatFactory 心跳任务构建工厂
     * @param connectStatusListener 连接状态回调
     * @param otherMsgCallback 非task队列所属的消息回调
     */
    fun createTcpNetHub(
        context: Context,
        options: NetHubOptions,
        heartbeatFactory: HeartbeatFactory,
        connectStatusListener: ConnectStatusListener? = null,
        otherMsgCallback: OtherMsgCallback? = null
    ): INetHubInterface {
        return TcpNetHub().also {
            it.init(
                context = context,
                options = options,
                heartbeatFactory = heartbeatFactory,
                connectStatusListener = connectStatusListener,
                otherMsgCallback = otherMsgCallback
            )
        }
    }
}
